package com.cloudxingkong.dianyinke.NewTeacher.Ui;

import android.content.Intent;
import android.graphics.Color;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.cloudxingkong.dianyinke.NewTeacher.Fragment.PingJiaFragment;
import com.cloudxingkong.dianyinke.NewTeacher.Fragment.DongTaiFragment;
import com.cloudxingkong.dianyinke.R;

/**
 * 我的圈子
 */
public class MineCircleActivity extends AppCompatActivity implements View.OnClickListener {

    private RadioButton dongtai;
    private RadioButton pingjia;
    private RadioGroup radioGroup;
    private ImageButton mc_back;
    private ImageButton mc_messages;

    private PingJiaFragment pingJiaFragment;
    private DongTaiFragment dongTaiFragment;
    private FragmentManager supportFragmentManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_circle);
        radioGroup = (RadioGroup) findViewById(R.id.mc_rg);
        dongtai = (RadioButton) findViewById(R.id.mc_rb_dongtai);
        pingjia = (RadioButton) findViewById(R.id.mc_rb_pingjia);
        mc_back = (ImageButton) findViewById(R.id.mc_back);
        mc_messages = (ImageButton) findViewById(R.id.mc_messages);
        mc_back.setOnClickListener(this);
        mc_messages.setOnClickListener(this);

        pingJiaFragment = new PingJiaFragment();
        dongTaiFragment = new DongTaiFragment();
        supportFragmentManager = getSupportFragmentManager();
        FragmentTransaction transaction = supportFragmentManager.beginTransaction();
        transaction.replace(R.id.mc_framelayout, pingJiaFragment).commit();

        final int color = ContextCompat.getColor(this, R.color.colorGreen);
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.mc_rb_dongtai:
                        dongtai.setTextColor(color);
                        pingjia.setTextColor(Color.WHITE);
                        FragmentTransaction transaction1 = supportFragmentManager.beginTransaction();
                        transaction1.replace(R.id.mc_framelayout, dongTaiFragment);
                        transaction1.commit();
                        break;
                    case R.id.mc_rb_pingjia:
                        pingjia.setTextColor(color);
                        dongtai.setTextColor(Color.WHITE);
                        FragmentTransaction transaction2 = supportFragmentManager.beginTransaction();
                        transaction2.replace(R.id.mc_framelayout, pingJiaFragment);
                        transaction2.commit();
                        break;
                }
            }
        });
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.mc_back:
                finish();
                break;
            case R.id.mc_messages:
                startActivity(new Intent(this, MineMessageActivity.class));
                break;
        }
    }
}
